/**
 * Created by lwy on 2017/6/11.
 */
var password;
var flag = true;
var flag2 = true;
var detail=decodeURI(decodeURI(window.location.href)).split('=');
var code = detail[1].split('&')[0];
var name = detail[2].split('&')[0];
var goodsName = detail[3].split('&')[0];
var goodsNum = detail[4].split('&')[0];
var goodsPrice = detail[5].split('&')[0];
var total = detail[6].split('&')[0];
var payMoney = detail[7].split('&')[0];
var tips = detail[8].split('&')[0];
if(tips==''){
    $('#tipsBox').hide();
}
var ShopName = detail[9].split('&')[0];
var managerName = detail[10].split('&')[0];
var id = detail[11];
$('#name').html(name);
$('#code').html(code);
$('#goodsName').html(goodsName);
$('#goodsNum').html(goodsNum);
$('#goodsPrice').html(goodsPrice);
$('#total').html(total);
$('#payMoney').html(payMoney);
$('#tips').html(tips);ShopName
$('#ShopName').html(ShopName);
$('#managerName').html(managerName);

//提交审核
var id = GetQueryString('id');
//修改弹出框默认input类型为password
document.getElementById("promptBtn").addEventListener('tap', function() {
    if(flag!=true){
        mui.toast('正在审核，请稍候...');
        return;
    }
    flag=false;
    mui.prompt(' ','请输入交易密码','请输入交易密码',['取消','确定'],function(e){
            if (e.index == 1) {
                $.ajax({
                    url: '/user/userLoginKey.json',
                    dataType: 'json',
                    data: {
                        name: getItem('phone'),
                    },
                    success: function (data) {
                        if (data.code != 1) {
                            mui.toast(data.msg);
                            flag=true;
                            return;
                        }
                        if (data.code == 1) {
                            password = calcMD5(e.value + data.datas.userKey, 32);
                            $.ajax({
                                url:'/zuoDanC/zuoDanShenHe.json',
                                dataType:'json',
                                data:{
                                    token:getItem('token'),
                                    zuoDanId:id,
                                    tradePassword: password,
                                },
                                success:function(data){
                                    if(data.code==-1){
                                        window.location.href="login.html"
                                    }
                                    if(data.code==1){
                                        mui.alert('审核成功',function(){
                                            window.location.href="check-success.html?id="+id;
                                        });
                                    }
                                    if(data.code==0){
                                        mui.toast(data.msg);
                                        flag=true;
                                        return;
                                    }
                                }
                            })
                        }
                    }
                })
            } else {

            }
    })
    document.querySelector('.mui-popup-input input').type='password'
})

//拒绝审核
document.getElementById('refuse').addEventListener('tap',function(e){
    if(flag2!=true){
        mui.toast('正在请求，请稍候...');
        return;
    }
    flag2=false;
    mui.prompt(' ','请输入拒绝原因', '请输入拒绝原因', ['取消','确定'], function(e){
        if (e.index == 1) {
                        $.ajax({
                            url:'/zuoDanC/rejectZuoDan.json',
                            dataType:'json',
                            data:{
                                token:getItem('token'),
                                zuoDanId:id,
                                illustrate: e.value,
                            },
                            type:'post',
                            success:function(data){
                                if(data.code==-1){
                                    window.location.href="login.html"
                                }
                                if(data.code==1){
                                    mui.alert('已拒绝',function(){
                                        window.location.href="makeorderCheck-list.html"
                                    });
                                }
                                if(data.code==0){
                                    mui.toast(data.msg);
                                    flag2=true;
                                    return;
                                }
                            }
                        })
        } else {

        }
    })
})